package algorithm.leetcode.I1to100;

import java.util.LinkedList;
import java.util.List;

public class Q77 {

    private final List<List<Integer>> result = new LinkedList<>();

    public List<List<Integer>> combine(int n, int k) {

        int[] candidates = new int[n];
        for (int i = 0; i < n; i++) {
            candidates[i] = i+1;
        }

        dfs(candidates, new LinkedList<>(), 0, k);
        return result;
    }

    private void dfs(int[] candidates,
                     List<Integer> current,
                     int searchFrom,
                     int targetLength) {
        if (current.size() == targetLength) {
            result.add(new LinkedList<>(current));
            return;
        }

        for (int i = searchFrom; i < candidates.length; i++) {
            current.add(candidates[i]);
            dfs(candidates, current, i+1, targetLength);
            current.remove(current.size()-1);
        }

    }

    public static void main(String[] args) {
        Q77 sevenSeven = new Q77();
        List<List<Integer>> combine = sevenSeven.combine(4, 2);
        System.out.println(combine);
    }


}
